module("Basic Template Tests ", {
	setup : function() {
		Assert.assertsOn();
		Logger.level(Logger.DEBUG);
		lastLog = null;
	},
	teardown : function() {
		Assert.assertsOff();
		lastLog = null;
	}
});

test("basic clone", function() {

	$("#templates").template();
	var $test1 = $("").template("clone", {
		target:"test1"
	});

	equal($test1.text(), "This is a test");
	equal($test1.prop('tagName'), "DIV");
});

test("basic clone and bind", function() {

	$("#templates").template();
	$("#content").empty();

	var $test = $("").template("clone", {
		target: "test2"
	});

	ok($test, "Expected to clone an element called test2");
	$test.template("bind", {
		"test-link-text":"click me!",
		"test-href":"http://google.com"
	});

	equal($test.find("a").text(), "click me!");
	equal($test.find("a").attr('href'), "http://google.com");
});

test("basic clone and function apply", function() {
	$("#templates").template();
	$("#content").empty();

	var $test = $("").template("clone", {
		target: "test3"
	});
	
	$test.template("bind", {
		"test-button":function($element) {
			$element.bind("click", function() {alert("Clicked");})
		},
		"button-label":"click me!"
	})

	equal($test.find("button").text(), "click me!");
});

test("advanced clone and function apply", function() {

	$("#templates").template();
	$("#content").empty();

	var $test = $("").template("clone", {
		target: "test4"
	});
	var $paragraph = null;
	
	ok($test, "Expected to clone an element called test4");
	$test.template("bind", {
		"test-href":"http://google.com/",
		"test-link-text":"Click For Google",
		"main-div": function($element) {
			$paragraph = $element;
		},
		"test-function":function($element) {
			$element.text("new text");
		}
	});
	
	equal($paragraph.find("a").text(), "Click For Google");
});

test("test iterators", function() {
	
	$("#templates").template();
	$("#content").empty();
	
	var $div = $("").template("clone", {
		target: "test5"
	});
	
	var data = {
		"test-array":[
		  		    {
				    	"test-text1":"this is a test 1A",
					    "test-text2":"this is a test 1B"
				    },
				    {
				    	"test-text1":"this is a test 2A",
					    "test-text2":"this is a test 2B"
				    },
				    {
				    	"test-text1":"this is a test 3A",
					    "test-text2":"this is a test 3B"
				    }

		]
	}
	$div.template("bind", data);
	
	$("#content").append($div);
	ok(true);
});

